﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class RecordTypeOut : IEquatable<RecordTypeOut>
    {
        public void ImportList(List<Classes.RecordTypeOut> RTOList)
        {
            
            var mdb = new MedregDBDataContext();
            var ListRTO = new List<RecordTypeOut>();
            foreach (var rto in RTOList)
            {
                RecordTypeOut rto1 = new RecordTypeOut() { ID = rto.ID, Name = rto.Name };
                RecordTypeOut query;

                if (mdb.RecordTypeOut.LongCount() == 0)
                {
                    mdb.RecordTypeOut.InsertOnSubmit(rto1);
                }
                else
                {
                    try
                    {
                        query = mdb.RecordTypeOut.Single(l => l.ID == rto1.ID);
                        query.Name = rto1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListRTO.Contains(rto1))
                        {
                            mdb.RecordTypeOut.InsertOnSubmit(rto1);
                            ListRTO.Add(rto1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(RecordTypeOut other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
